# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Jürgen Pfeifer <juergen@familiepfeifer.de>

_realname=qrupdate
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}-svn")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-svn")
pkgver=1.1.2
_rev=r28
pkgrel=1
pkgdesc="qrupdate is a Fortran library for fast updates of QR and Cholesky decompositions (mingw-w64)"
arch=('any')
url="https://qrupdate.sourceforge.io/"
options=('strip' 'staticlibs')
license=('GPL' 'LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc-fortran")
depends=("${MINGW_PACKAGE_PREFIX}-openblas"
         "${MINGW_PACKAGE_PREFIX}-gcc-libgfortran")
source=("${_realname}-${pkgver}.zip::https://sourceforge.net/code-snapshots/svn/q/qr/qrupdate/code/qrupdate-code-${_rev}.zip")
sha256sums=('7f9bc0c9b978febc03da6c068bb39483ddb630fbfb4b0fbf1e7aa41efa3060e6')

build() {
  mv "${srcdir}/qrupdate-code-${_rev}" "${srcdir}/${_realname}-${pkgver}"
  mkdir -p ${srcdir}/build-${CARCH} && cd ${srcdir}/build-${CARCH}
  cp -pR ../${_realname}-${pkgver}/* .
  make FPICFLAGS="" lib
  gfortran -shared -o lib${_realname}.dll -Wl,--out-implib,lib${_realname}.dll.a src/*.o -lopenblas -lgfortran
}

package() {
  cd ${srcdir}/build-${CARCH}
  mkdir -p ${pkgdir}${MINGW_PREFIX}/bin
  mkdir -p ${pkgdir}${MINGW_PREFIX}/lib
  cp -pf lib${_realname}.dll ${pkgdir}${MINGW_PREFIX}/bin
  cp -pf lib${_realname}*.a ${pkgdir}${MINGW_PREFIX}/lib
  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}
  cp -pf ${srcdir}/${_realname}-${pkgver}/COPYING* \
    ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}
}
